using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using emp.ProcessFlow;
using emp.Model;
using System.Globalization;
using emp.SqlServerDAL;
using emp.BLL;

public partial class DataTransfer_DDR_Add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //if (HttpContext.Current.Session["USER_KEY"] == null)
            //{
            //    Response.Redirect("\\logon.aspx");
            //    return;
            //}
            string sDDRSourceID = "";
            if (Request.Params["DDR_Source_ID"] == "" || Request.Params["DDR_Source_ID"] == null)
            {
                sDDRSourceID = "0";
            }
            else
            {
                sDDRSourceID = Request.Params["DDR_Source_ID"];
            }
           //DISMController icon = new DISMController();
           // icon.DropDownListBind(this.DDR_Source_ID, sDDRSourceID);

           this.DDR_Source_ID.Items.Clear();
           this.DDR_Source_ID.Items.Add(new ListItem("select", ""));
           this.DDR_Source_ID.Items.Add(new ListItem("Web&IB Data", "0"));
           //CampaignBll cpn = new CampaignBll();
           //IList cpnlist = cpn.getCampaignList();         

           //for (int i = 0; i < cpnlist.Count; i++)
           //{
           //    this.DDR_Source_ID.Items.Add(new ListItem(((CampaignInfo)cpnlist[i]).CAM_NAME, ((CampaignInfo)cpnlist[i]).CAM_QUR_ID.ToString()));               
           //}
        }
    }

    protected void Submit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            int iDDRSourceID = 0;
            string sDDRName = "";
            string sDDRSourceTable = "";
            string sDDRDestinationTable = "";
            string sDDRSourceKey = "";
            string sDDRDestinationKey = "";
            string sDDRSourceField1 = "";
            string sDDRSourceField2 = "";
            string sDDRSourceField3 = "";
            string sDDRSourceField4 = "";
            string sDDRSourceField5 = "";
            string sDDRSourceField6 = "";
            string sDDRSourceField7 = "";
            string sDDRSourceField8 = "";
            string sDDRSourceField9 = "";
            string sDDRSourceField10 = "";
            string sDDRDestinationField1 = "";
            string sDDRDestinationField2 = "";
            string sDDRDestinationField3 = "";
            string sDDRDestinationField4 = "";
            string sDDRDestinationField5 = "";
            string sDDRDestinationField6 = "";
            string sDDRDestinationField7 = "";
            string sDDRDestinationField8 = "";
            string sDDRDestinationField9 = "";
            string sDDRDestinationField10 = "";
            int iDDRSelf = 0;
            int iDDRType = 0;
            string sDDRIsValid = "1";
            string sDDRIsValidField = "";
            int iDDRDupType = 1;
            string sDDRDupCon = "";
            int iDDRSeq = 0;

            if (DDR_Name.Text == "" || DDR_Name.Text == null)
            {
                sDDRName = "";
            }
            else 
            {
                sDDRName = DDR_Name.Text;
            }

            if (DDR_Source_Table.Text == "" || DDR_Source_Table.Text == null)
            {
                sDDRSourceTable = "";
            }
            else
            {
                sDDRSourceTable = DDR_Source_Table.Text;
            }

            if (DDR_Destination_Table.Text == "" || DDR_Destination_Table.Text == null)
            {
                sDDRDestinationTable = "";
            }
            else
            {
                sDDRDestinationTable = DDR_Destination_Table.Text;
            }

            if (DDR_Source_Key.Text == "" || DDR_Source_Key.Text == null)
            {
                sDDRSourceKey = "";
            }
            else
            {
                sDDRSourceKey = DDR_Source_Key.Text;
            }

            if (DDR_Destination_Key.Text == "" || DDR_Destination_Key.Text == null)
            {
                sDDRDestinationKey = "";
            }
            else
            {
                sDDRDestinationKey = DDR_Destination_Key.Text;
            }

            if (DDR_Source_Field1.Text == "" || DDR_Source_Field1.Text == null)
            {
                sDDRSourceField1 = "";
            }
            else
            {
                sDDRSourceField1 = DDR_Source_Field1.Text;
            }

            if (DDR_Source_Field2.Text == "" || DDR_Source_Field2.Text == null)
            {
                sDDRSourceField2 = "";
            }
            else
            {
                sDDRSourceField2 = DDR_Source_Field2.Text;
            }

            if (DDR_Source_Field3.Text == "" || DDR_Source_Field3.Text == null)
            {
                sDDRSourceField3 = "";
            }
            else
            {
                sDDRSourceField3 = DDR_Source_Field3.Text;
            }

            if (DDR_Source_Field4.Text == "" || DDR_Source_Field4.Text == null)
            {
                sDDRSourceField4 = "";
            }
            else
            {
                sDDRSourceField4 = DDR_Source_Field4.Text;
            }

            if (DDR_Source_Field5.Text == "" || DDR_Source_Field5.Text == null)
            {
                sDDRSourceField5 = "";
            }
            else
            {
                sDDRSourceField5 = DDR_Source_Field5.Text;
            }

            if (DDR_Source_Field6.Text == "" || DDR_Source_Field6.Text == null)
            {
                sDDRSourceField6 = "";
            }
            else
            {
                sDDRSourceField6 = DDR_Source_Field6.Text;
            }

            if (DDR_Source_Field7.Text == "" || DDR_Source_Field7.Text == null)
            {
                sDDRSourceField7 = "";
            }
            else
            {
                sDDRSourceField7 = DDR_Source_Field7.Text;
            }

            if (DDR_Source_Field8.Text == "" || DDR_Source_Field8.Text == null)
            {
                sDDRSourceField8 = "";
            }
            else
            {
                sDDRSourceField8 = DDR_Source_Field8.Text;
            }

            if (DDR_Source_Field9.Text == "" || DDR_Source_Field9.Text == null)
            {
                sDDRSourceField9 = "";
            }
            else
            {
                sDDRSourceField9 = DDR_Source_Field9.Text;
            }

            if (DDR_Source_Field10.Text == "" || DDR_Source_Field10.Text == null)
            {
                sDDRSourceField10 = "";
            }
            else
            {
                sDDRSourceField10 = DDR_Source_Field10.Text;
            }


            if (DDR_Destination_Field1.Text == "" || DDR_Destination_Field1.Text == null)
            {
                sDDRDestinationField1 = "";
            }
            else
            {
                sDDRDestinationField1 = DDR_Destination_Field1.Text;
            }

            if (DDR_Destination_Field2.Text == "" || DDR_Destination_Field2.Text == null)
            {
                sDDRDestinationField2 = "";
            }
            else
            {
                sDDRDestinationField2 = DDR_Destination_Field2.Text;
            }

            if (DDR_Destination_Field3.Text == "" || DDR_Destination_Field3.Text == null)
            {
                sDDRDestinationField3 = "";
            }
            else
            {
                sDDRDestinationField3 = DDR_Destination_Field3.Text;
            }

            if (DDR_Destination_Field4.Text == "" || DDR_Destination_Field4.Text == null)
            {
                sDDRDestinationField4 = "";
            }
            else
            {
                sDDRDestinationField4 = DDR_Destination_Field4.Text;
            }


            if (DDR_Destination_Field5.Text == "" || DDR_Destination_Field5.Text == null)
            {
                sDDRDestinationField5 = "";
            }
            else
            {
                sDDRDestinationField5 = DDR_Destination_Field5.Text;
            }


            if (DDR_Destination_Field6.Text == "" || DDR_Destination_Field6.Text == null)
            {
                sDDRDestinationField6 = "";
            }
            else
            {
                sDDRDestinationField6 = DDR_Destination_Field6.Text;
            }


            if (DDR_Destination_Field7.Text == "" || DDR_Destination_Field7.Text == null)
            {
                sDDRDestinationField7 = "";
            }
            else
            {
                sDDRDestinationField7 = DDR_Destination_Field7.Text;
            }


            if (DDR_Destination_Field8.Text == "" || DDR_Destination_Field8.Text == null)
            {
                sDDRDestinationField8 = "";
            }
            else
            {
                sDDRDestinationField8 = DDR_Destination_Field8.Text;
            }

            if (DDR_Destination_Field9.Text == "" || DDR_Destination_Field9.Text == null)
            {
                sDDRDestinationField9 = "";
            }
            else
            {
                sDDRDestinationField9 = DDR_Destination_Field9.Text;
            }


            if (DDR_Destination_Field10.Text == "" || DDR_Destination_Field10.Text == null)
            {
                sDDRDestinationField10 = "";
            }
            else
            {
                sDDRDestinationField10 = DDR_Destination_Field10.Text;
            }

            if (DDR_IsValid_Field.Text == "" || DDR_IsValid_Field.Text == null)
            {
                sDDRIsValidField = "";
            }
            else
            {
                sDDRIsValidField = DDR_IsValid_Field.Text;
            }
            iDDRSelf = Int32.Parse(DDR_Self.SelectedValue);
            iDDRType = Int32.Parse(DDR_Type.SelectedValue);
            sDDRIsValid = "1";
            string sDDRBatchField = "";
            if (DDR_Batch_Field.Text == "" || DDR_Batch_Field.Text == null)
            {
                sDDRBatchField = "";
            }
            else
            {
                sDDRBatchField = DDR_Batch_Field.Text;
            }
            iDDRSourceID = Int32.Parse(DDR_Source_ID.SelectedValue);
            iDDRDupType = Int32.Parse(DDR_Dup_Type.SelectedValue);
            if (DDR_Dup_Con.Text == "" || DDR_Dup_Con.Text == null)
            {
                sDDRDupCon = "";
            }
            else
            {
                sDDRDupCon = DDR_Dup_Con.Text;
            }
            if (DDR_Seq.Text == "" || DDR_Seq.Text == null)
            {
                iDDRSeq = 0;
            }
            else
            {
                iDDRSeq = Int32.Parse(DDR_Seq.Text);
            }

            DDRInfo ddrinfo = new DDRInfo(
                iDDRSourceID,
                sDDRName,
                sDDRSourceTable,
                sDDRSourceKey,
                sDDRSourceField1,
                sDDRSourceField2,
                sDDRSourceField3,
                sDDRSourceField4,
                sDDRSourceField5,
                sDDRSourceField6,
                sDDRSourceField7,
                sDDRSourceField8,
                sDDRSourceField9,
                sDDRSourceField10,
                sDDRDestinationTable,
                sDDRDestinationKey,
                sDDRDestinationField1,
                sDDRDestinationField2,
                sDDRDestinationField3,
                sDDRDestinationField4,
                sDDRDestinationField5,
                sDDRDestinationField6,
                sDDRDestinationField7,
                sDDRDestinationField8,
                sDDRDestinationField9,
                sDDRDestinationField10,
                iDDRSelf,
                iDDRType,
                sDDRIsValid,
                sDDRBatchField,
                sDDRIsValidField,
                iDDRDupType,
                sDDRDupCon,
                iDDRSeq);

            DDRController iCon = new DDRController();
            iCon.CreateDDR(ddrinfo);
            Response.Redirect("DDR_List.aspx?page=0");
        }
    }
    protected void DDR_Source_ID_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.DDR_Source_ID.SelectedValue == "0")
        {
            this.DDR_Source_Table.Text = "IMPORT_TEMP_DETAIL";
            this.DDR_Source_Key.Text = "ITD_ID";
        }
        else
        {
            this.DDR_Source_Table.Text = "ND_QUEST_"+this.DDR_Source_ID.SelectedValue;
            this.DDR_Source_Key.Text = "NDQ_ID"; 
        }      
    }
}
